<include file="public@header" />
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" class="pic" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li ><a href="{:url('goods/index')}">品牌列表</a></li>
        <li class="active"><a href="#">添加商品</a></li>
    </ul>
    <form class="form-horizontal js-ajax-form margin-top-20" role="form"  method="post">
        <fieldset>
            <input type="hidden" id="goods_guid" value="{$date.goods_guid}">
            <div class="tabbable">
                <div class="tab-content">
                    <div class="tab-pane active" id="A">
                        <div class="form-group">
                            <input type="hidden" id="brands" value="">
                            <label for="input-site-g_goodsname" class="col-sm-2 control-label"><span class="form-required">*</span>商品名称</label>
                            <div class="col-md-6 col-sm-10">
                                <input type="text" class="form-control"  name="g_goodsname" id="g_goodsname" value="{$date.goods_name}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>规格</label>
                            <div class="col-md-6 col-sm-10">
                                <select class="form-control" name="format" id="format" style="width: 140px;">
                                    <foreach name="format" item="format">
                                        <if condition="$date.g_format eq $format.f_id">
                                        <option selected value='{$format.for_guid}'>{$format.f_name}</option>
                                        <else/>
                                            <option selected value='{$format.for_guid}'>{$format.f_name}</option>
                                        </if>
                                    </foreach>
                                </select> &nbsp;
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>原价</label>
                            <div class="col-md-6 col-sm-10">
                                <input type="text" class="form-control" id="price" name="price" value="{$date.g_price}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required"></span>会员价</label>
                            <div class="col-md-6 col-sm-10">
                                <input type="text" class="form-control" id="vipprice" name="vipprice" value="{$date.g_newprice}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>类别</label>
                            <div class="col-md-6 col-sm-10">
                                <select class="form-control" name="category" id="category" style="width: 140px;">
                                    <foreach name="category" item="category">
                                        <if condition="$date.g_category eq $category.id">
                                        <option selected value='{$category.gc_guid}'>{$category.gc_name}</option>
                                        <else/>
                                            <option  value='{$category.gc_guid}'>{$category.gc_name}</option>
                                        </if>
                                    </foreach>
                                </select> &nbsp;
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>品牌</label>
                            <div class="col-md-6 col-sm-10">
                                <select class="form-control" name="brandid" id="brandid" style="width: 140px;">
                                    <foreach name="brand" item="brand">
                                        <if condition="$date.brand_id eq $brand.id">
                                        <option selected value='{$brand.guid}'>{$brand.name}</option>
                                        <else/>
                                            <option  value='{$brand.guid}'>{$brand.name}</option>
                                        </if>
                                    </foreach>
                                </select> &nbsp;
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_pic" class="col-sm-2 control-label"><span class="form-required"></span>商品图片</label>
                            <div class="info_content" id="Personal">
                                <div class="col-md-6 col-sm-10">
                                    <tr>
                                        <!--  <th>相册</th> -->
                                        <td>
                                            <a href="javascript:uploadOneImage('图片上传','#js-thumbnail-input');">
                                                <if condition="empty($date.goods_prc)">
                                                    <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                                         id="js-thumbnail-input-preview"
                                                         width="135" style="cursor: pointer"/>
                                                    <else/>
                                                    <img src="{:cmf_get_image_preview_url($date.goods_prc)}"
                                                         id="js-thumbnail-input-preview"
                                                         width="135" style="cursor: pointer"/>
                                                </if>
                                            </a>
                                        </td>
                                    </tr>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>库存</label>
                            <div class="col-md-6 col-sm-10">
                                <input type="text" class="form-control" id="stock" name="stock" value="{$date.number}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required"></span>商品简介</label>
                            <div class="col-md-6 col-sm-10">
                               <textarea class="form-control" name="desc" id="desc" style="height: 80px;"
                                         placeholder="商品简介">{$date.desc}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required"></span>商品状态</label>
                            <div class="col-md-6 col-sm-10">
                                <select class="form-control" name="status" id="status" style="width: 140px;">
                                    <if condition="$date.status eq 0">
                                    <option selected  value='0'>下架</option>
                                    <else/>
                                     <option value='0'>下架</option>
                                    </if>
                                    <if condition="$date.status eq 1">
                                    <option selected value='1'>上架</option>
                                    <else/>
                                     <option  value='1'>上架</option>
                                    </if>
                                    <if condition="$date.status eq -1">
                                    <option selected value='-1'>审核中</option>
                                     <else/>
                                     <option  value='-1'>审核中</option>
                                    </if>
                                    <if condition="$date.status eq -2">
                                    <option selected value='-2'>审核失败</option>
                                    <else/>
                                        <option  value='-2'>审核失败</option>
                                    </if>
                                </select> &nbsp;
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>是否能预约</label>
                            <div class="col-md-6 col-sm-10">
                                <select class="form-control" name="appointment" id="appointment" style="width: 140px;">
                                  <if condition="$date.appointment eq 1">
                                    <option selected value='1'>是</option>
                                    <option value='2'>否</option>
                                  <else/>
                                      <option  value='1'>是</option>
                                      <option selected value='2'>否</option>
                                  </if>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="button" id="sub" class="btn btn-primary js-ajax-submit" data-refresh="1">{:lang('SAVE')}</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
    <!-- 预览js -->
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
</body>
<script>
    $('#sub').click(function(){
        var data= new Array();
        $('#prices li').each(function(index)
        {
            var zz=/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
            var price=$(this).find('.price').val();
            var pd=zz.test(price);
            if(pd ==false && price != '')
            {
                alert('请输入纯数字');
                return false;
            }
            var vipprice=$(this).find('.vipprice').val();
            var vip=zz.test(vipprice);
            if(vip ==false && vipprice != '')
            {
                alert('请输入纯数字');
                return false;
            }
            var format=$(this).find('.format').val();
            data.push(format+','+price+','+vipprice);
        });
        var goodsname=$('#g_goodsname').val();
        if(goodsname == '')
        {
            alert('商品名称不能为空！');
            return false;
        }
        var goods_guid=$('#goods_guid').val();
        var format=$('#format').val();
        var price=$('#price').val();
        var vipprice=$('#vipprice').val();
        var brandid=$('#brandid').val();
        var stock=$('#stock').val();
        var desc=$('#desc').val();
        var statue=$('#status').val();
        var pic=$('#js-thumbnail-input-preview').attr('src');
        var appointment=$('#appointment').val();
        var category=$('#category').val();
        $.post("{:url('goods/detailpost')}",{goods_guid:goods_guid,g_format:format,g_price:price,g_newprice:vipprice,goods_name:goodsname,brand_id:brandid,number:stock,desc:desc,status:statue,goods_prc:pic,g_category:category,appointment:appointment},function(date){
            if(date == 0)
            {
                alert('修改失败');
            }else{
                alert('修改成功');
                window.location="{:url('goods/index')}";
            }

        },'json')
    })
</script>
</html>